package com.example.sticker;

import android.app.Activity;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.graphics.RectF;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

public class MainActivity extends Activity implements OnImageCloseListener {
	private StickerView mStickerView;
	private ImageView mImage;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		mStickerView = (StickerView) findViewById(R.id.sticker);
		mStickerView.setCloseListener(this);
		mImage = (ImageView) findViewById(R.id.imgfilter);
		mImage.setImageResource(R.drawable.camera_shoot_buttonbar_button_default);
	}
	
	public void onSetStickerClick(View v) {
		mStickerView.setStickerBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.test2));
		init();
	}
	
	private void init() {
	    Matrix matrix = mImage.getImageMatrix();
	    mImage.setVisibility(View.VISIBLE);
	    RectF rectF = new RectF(0.0F, 0.0F, mImage.getWidth(), mImage.getHeight());
	    matrix.mapRect(rectF);
	    mStickerView.init(rectF.bottom - rectF.top, rectF.right - rectF.left);
	}
	
	public void closeStickerImage() {
		if (mImage != null) {
			mImage.setVisibility(View.GONE);
		}
	}
}
